import {PageContainer, ProColumns, ProTable} from "@ant-design/pro-components";
import {globalLoadTableApi, globalLoadTableApiCode} from "@/services/admin-api/globalApi";
import {useAccess} from "umi";

type ShortMessage = {
  smId: number;
  smPhone: string;
  smContent: string;
  smProviderType: number;
  smCode: string;
  smArrive: boolean;
  smCheck: boolean;
  delFlag: boolean;
  createTime: string;
  createUserId: number;
  createUserName: string;
  updateTime: string;
  updateUserId: number;
  updateUserName: string;
};

export default () => {
  const access = useAccess()

  const columns: ProColumns<ShortMessage>[] = [
    // {title: '', valueType: 'indexBorder'},
    {title: '短信ID', dataIndex: 'smId', valueType: 'digit'},
    {title: '手机号', dataIndex: 'smPhone', valueType: 'text'},
    {title: '内容', dataIndex: 'smContent', valueType: 'text'},
    {
      title: '供应商',
      dataIndex: 'smProviderType',
      valueType: 'select',
      valueEnum: {all: {text: '全部'}, 0: {text: '默认'}}
    },
    {title: '验证码', dataIndex: 'smCode', valueType: 'text'},
    {title: '送达', dataIndex: 'smArrive', valueType: 'switch', render: (_, val) => val.smArrive.toString()},
    {
      title: '验证',
      dataIndex: 'smCheck',
      valueType: 'switch',
      render: (_, val) => val.smCheck ? val.smCheck.toString() : ''
    },
    // {title: '逻辑删除', dataIndex: 'delFlag', valueType: 'switch', render: (_, val) => val.delFlag.toString()},
    {title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true,},
    {
      title: '创建时间', dataIndex: 'createTime', valueType: 'dateTimeRange', hideInTable: true, search: {
        transform: (value) => {
          return {
            createTimeStart: value[0],
            createTimeEnd: value[1],
          };
        },
      },
    },
    {title: '创建用户ID', dataIndex: 'createUserId', valueType: 'digit', hideInSearch: true,},
    {title: '创建用户', dataIndex: 'createUserName', valueType: 'text', hideInSearch: true,},
    {title: '更新时间', dataIndex: 'updateTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '更新用户ID', dataIndex: 'updateUserId', valueType: 'digit', hideInSearch: true,},
    {title: '更新用户', dataIndex: 'updateUserName', valueType: 'text', hideInSearch: true,},
  ];

  return <PageContainer header={{title: '', breadcrumb: {},}}>
    <ProTable<ShortMessage>
      columns={columns}
      search={{span: 4}}
      request={async (param) => globalLoadTableApiCode('/shortMessage/table', 'short:list:search', access, param)}
      rowKey={(record) => record.smId}
      columnsState={{
        defaultValue: {
          delFlag: {show: false},
          createUserId: {show: false},
          updateUserId: {show: false}
        }
      }}/>
  </PageContainer>
}
